package com.ztk.threadbasic.volitale;

import com.mchange.v2.lang.ThreadUtils;
import org.apache.poi.ss.formula.functions.T;

import java.util.concurrent.TimeUnit;

/**
 * 待删除的注释
 */
public class Volitale03 {

    private static volatile boolean flag = true;

    private void refresh() {
        flag = false;
        System.out.println(Thread.currentThread().getName() + "修改flag:"+flag);
    }

    private void load() throws InterruptedException {
        while(flag) {
            System.out.println("load...");
            TimeUnit.SECONDS.sleep(2);
        }
        System.out.println(Thread.currentThread().getName() + "load执行结束：flag="+flag);
    }

    public static void main(String[] args) throws InterruptedException {
        Volitale03 volitale03A = new Volitale03();
        Volitale03 volitale03B = new Volitale03();
        Thread threadA = new Thread(() -> {
            try {
                volitale03A.load();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }, "threadA");

        Thread threadB = new Thread(() -> {
            volitale03B.refresh();
        }, "threadB");

        threadA.start();
        TimeUnit.SECONDS.sleep(5);
        threadB.start();
        TimeUnit.SECONDS.sleep(10);
    }
}
